<?php

/**
 * 微信支付
 */

namespace pay;

class WeChat extends PayBase {

    // 配置文件
    protected $configs = [
        'appid'            => 'wx83ffbd4d3d50f6c1', // 公众账号ID
        'mch_id'           => '1602547044', // 商户号
        'spbill_create_ip' => '127.0.0.1', // ip地址
        'notify_url'       => 'http://app.fpaiyun.com/test/pay/notify_url.json', // 回调地址
        'key'              => '0e4fe3ce107dba0f19f985391dbd0b55', // 支付密钥
        'sign_type'        => 'MD5', // 签名类型
    ];

    /**
     * 设置参数
     * @param $data
     * @return mixed|void
     */
    protected function setData($data) {
        parent::setData($data);
        $this->data['trade_type'] = 'NATIVE';
    }

    /**
     * 统一支付
     * @return bool
     */
    public function unifiedOrder() {
        $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
        $this->setTime();
        $this->data['sign'] = $this->makeSign();
        $xmlData = $this->toXml();
        $res = $this->request($url, $xmlData);
        return $res;
    }

}